<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app"></div>
  <script src="./package/vue.js"></script>
  <script>
    var bus = new Vue() 
    Vue.component('bother1', {
      data() {
        return {
          msg: ''
        }
      },
      template: `
        <div class="bother1">
          <p>我是bother1组件</p>
          <p>接收到bother2组件的信息：{{this.msg}}</p>
          <button @click="sendData">传递信息给bother2组件</button>
        </div>
      `,
      mounted() {
        bus.$on('one', (msg) => {
          this.msg = msg
        })
      },
      methods: {
        sendData() {
          bus.$emit('two', '我是one')
        }
      }
    })
    Vue.component('bother2', {
      data() {
        return {
          msg: ''
        }
      },
      template: `
        <div class="bother2">
          <p>我是bother2组件</p>
          <p>接收到bother1组件的信息：{{this.msg}}</p>
          <button @click="sendData">传递信息给bother1组件</button>
        </div>
      `,
      mounted() {
        bus.$on('two', (msg) => {
          this.msg = msg
        })
      },
      methods: {
        sendData() {
          bus.$emit('one', '我是two')
        }
      }
    })
    var app = new Vue({
      el: '#app',
      template: `
        <div>
          <bother1></bother1>
          <bother2></bother2>
        </div>
      `
    })
  </script>
</body>
</html>